<?php if(!class_exists("View", false)) exit("no direct access allowed");?><main id="main" class="in">
    <div class="container-fluid">
        <div class="row">
            <div class="col-xs-3">
                <div class="panel">
                    <div class="panel-heading">
                        <div class="title"> 部门结构 </div>
                    </div>
                    <div class="panel-body">
                        <ul data-name="tree-dept" id="deptTree" class="tree" data-idx="0"></ul>
                        <div class="text-center">
                          <a href="<?php echo url(array('c'=>"System", 'a'=>"DepartmentBrowse", ));?>" class="btn btn-info btn-wide">维护部门</a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-9">
                <div class="panel">                    
                    <div class="panel-body">
                        <table class="table datatable userlist">
                            <thead>
                              <tr>
                                <th>ID</th>
                                <th>真实姓名</th>
                                <th>用户名</th>
                                <th>邮箱</th>
                                <th>电话</th>
                                <th>操作</th>
                              </tr>
                            </thead>
                            <tbody>
                              <?php if(!empty($result['data'])){ $_foreach_v_counter = 0; $_foreach_v_total = count($result['data']);?><?php foreach( $result['data'] as $k => $v ) : ?><?php $_foreach_v_index = $_foreach_v_counter;$_foreach_v_iteration = $_foreach_v_counter + 1;$_foreach_v_first = ($_foreach_v_counter == 0);$_foreach_v_last = ($_foreach_v_counter == $_foreach_v_total - 1);$_foreach_v_counter++;?>
                              <tr>
                                <td><?php echo htmlspecialchars($v['id'], ENT_QUOTES, "UTF-8"); ?></td>
                                <td><?php echo htmlspecialchars($v['realname'], ENT_QUOTES, "UTF-8"); ?></td>
                                <td><?php echo htmlspecialchars($v['account'], ENT_QUOTES, "UTF-8"); ?></td>
                                <td><?php echo htmlspecialchars($v['email'], ENT_QUOTES, "UTF-8"); ?></td>
                                <td><?php echo htmlspecialchars($v['mobile'], ENT_QUOTES, "UTF-8"); ?></td>
                                <td>
                                  <a href="<?php echo url(array('c'=>"System", 'a'=>"UserEdit", 'id'=>"", ));?><?php echo htmlspecialchars($v['id'], ENT_QUOTES, "UTF-8"); ?>" title="编辑用户" class="with-padding"><i class="icon-common-edit icon-edit"></i></a>
                                  <a href="<?php echo url(array('c'=>"System", 'a'=>"UserDel", 'id'=>"", ));?><?php echo htmlspecialchars($v['id'], ENT_QUOTES, "UTF-8"); ?>" title="编辑用户" class="with-padding"><i class="icon-common-trash icon-trash"></i></a>
                                </td>
                              </tr>
                              <?php endforeach; }?>
                            </tbody>
                          </table>
                          <?php if ($result['pager']) : ?>
                          <ul id="myPager" class="pager" data-ride="pager" data-link-Creator="?page={page}" data-page="<?php echo htmlspecialchars($result['pager']['current_page'], ENT_QUOTES, "UTF-8"); ?>" data-rec-total="<?php echo htmlspecialchars($result['pager']['total_count'], ENT_QUOTES, "UTF-8"); ?>" data-max-nav-count="<?php echo htmlspecialchars($result['pager']['total_page'], ENT_QUOTES, "UTF-8"); ?>" data-elements="prev_icon,page_of_total_text,next_icon"></ul>
                          <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    <input type="hidden" id="dept" value='<?php echo htmlspecialchars($dept, ENT_QUOTES, "UTF-8"); ?>'>
    <script src="http://p1.renbenzhihui.com/zui/js/all.js"></script>
        <script src="/i/js/util.js"></script>
        <script src="http://p1.renbenzhihui.com/zui/lib/datatable/zui.datatable.min.js"></script>
        <script>      
          $(function(){
              var data = JSON.parse($('#dept').val());
              var options = {
                  name: 'deptTree',
                  initialState: 'preserve',
                  data: data,
                  sortable: 
                  {
                      lazy: true,
                      nested: true,
                      canMoveHere: function($ele, $target)
                      {
                          if($ele && $target && $ele.parent().closest('li').attr('data-id') !== $target.parent().closest('li').attr('data-id')) return false;
                      }
                  },
                  itemCreator: function($li, item)
                  {
                      var link = item.id !== undefined ? ('<a href="<?php echo url(array('c'=>"System", 'a'=>"Index", 'deptId'=>"", ));?>'+item.id+'">' + item.name + '</a>') : ('<span class="tree-toggle">' + item.name + '</span>');
                      var $toggle = $('<span class="dept-name module-name" data-id="' + item.id + '">' + link + '</span>');
                      if(item.manager)
                      {
                          $toggle.append('&nbsp; <span class="dept-manager text-muted"><i class="icon icon-user"></i> ' + item.managerName + '</span>');
                      }
                      $li.append($toggle);
                      return true;
                  }
              }
          
              var $tree = $('#deptTree').tree(options);
          
              var tree = $tree.data('zui.tree');            
          
              $tree.on('mouseenter', 'li:not(.tree-action-item)', function(e)
              {
                  $('#deptTree').find('li.hover').removeClass('hover');
                  $(this).addClass('hover');
                  e.stopPropagation();
              });
              $('.userlist').datatable({
                checkable: true,
                sortable: true,
                minFixedLeftWidth: 300
              });
          });
          </script>
  </main>